package com.learn.lettuce.controller;


import java.util.Optional;
import javax.annotation.Resource;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @RequestMapping("/get")
    public String get(@RequestParam String redisKey){
        return Optional.ofNullable(redisTemplate.opsForValue().get(redisKey)).orElse("null").toString();
    }

    @RequestMapping("/set")
    public String set(@RequestParam String redisKey, @RequestParam String value) {
        redisTemplate.opsForValue().set(redisKey, value);
        return "success";
    }

}
